﻿@using FwProject.Settlement.Dto
@using FwProject.Distribution.Dto
@using FwProject.Core.SettlementInfoModel
@model Tuple<SettlementInfoDto, List<DistributionDetailsOutInputDto>>
@{
    ViewBag.Title = "收据[" + Model.Item1.CreationNumber + "]";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }

        .checked {
            position: absolute;
            top: 3px;
            left: 220px;
            height: 87px;
            width: 141px;
            background: url('/images/checked.gif') left top no-repeat;
            z-index: 9999;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    @if (Model.Item1.ExamineStatus == ExamineStatus.已审核)
                    {
                        <a class="btn btn-primary btn-xs" href="/Receipt/AntiCheck?id=@Model.Item1.Id">反审核</a>
                    }
                    else if (Model.Item1.ExamineStatus == ExamineStatus.未审核 || Model.Item1.ExamineStatus == ExamineStatus.已退回)
                    {
                        <button class="btn btn-primary btn-xs" id="btnExm">审核</button>
                    }
                </div>
            </div>
            <div class="ibox-content" style="height:700px">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" id="form" action="/Receipt/ToExamine?id=@Model.Item1.Id" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Post" data-ajax-mode="replace" data-ajax-success="FormAjaxCallbackgoback">
                        <input type="hidden" />
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">单号：</label>
                                <div class="input-group">
                                    <input type="text" name="CreationNumber" class="input-sm form-control" value="@Model.Item1.CreationNumber" readonly="readonly">
                                </div>
                                @if (Model.Item1.ExamineStatus == ExamineStatus.已审核)
                                {
                                    <div class="checked" id="check_icon"></div>
                                }
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">日期：</label>
                                <div class="input-group">
                                    <input type="text" name="CreationTime" class="input-sm form-control" value="@Model.Item1.CreationTime.ToString("yyyy-MM-dd")" readonly="readonly">
                                </div>
                            </div>
                            @if (Model.Item1.ExamineStatus == ExamineStatus.已审核)
                            {
                                <div class="col-md-4">
                                    <label class="control-label col-md-3">经办人：</label>
                                    <div class="input-group">
                                        <input type="text" name="DriverName" class="input-sm form-control" value="@Model.Item1.EmployeeDriverDao?.Name" readonly="readonly">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="col-md-4">
                                    <label class="control-label col-md-3">经办人：</label>
                                    <div class="input-group" style="width:162px">
                                        <input type="hidden" name="EmployeeDriverid" id="EmployeeDriverid" value="@Model.Item1.EmployeeDriverid" />
                                        <input type="text" id="dropdown-agentpeoperuserid" value="@Model.Item1.EmployeeDriverDao?.Name" class="form-control" onblur="blurEmpty()">
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown" style="line-height:1.455;padding:6px 12px;">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-right" role="menu" style="z-index: 9999;"></ul>
                                        </div>
                                    </div>
                                </div>
                            }
                        </div>
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">餐厅：</label>
                                <div class="input-group">
                                    <input type="text" name="RestaurantName" class="input-sm form-control" value="@Model.Item1.RestaurantInfoModel?.RestaurantName" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">配送日期：</label>
                                <div class="input-group">
                                    <input type="text" name="DeliveryDate" class="input-sm form-control" value="@Model.Item1?.DeliveryDate" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">整单金额：</label>
                                <div class="input-group">
                                    <input type="text" name="Totalprice" id="TotalPrice" class="input-sm form-control" value="@Model.Item1.Totalprice" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            @if (Model.Item1.ExamineStatus == ExamineStatus.已审核)
                            {
                                <div class="col-md-4">
                                    <label class="control-label col-md-3">制单优惠：</label>
                                    <div class="input-group">
                                        <input type="text" name="ReceivedDiscount" class="input-sm form-control" value="@(Model.Item1.Discountprice)" readonly>
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="col-md-4">
                                    <label class="control-label col-md-3">制单优惠：</label>
                                    <div class="input-group">
                                        <input type="text" name="ReceivedDiscount" id="ReceivedDiscount" class="input-sm form-control" value="@Model.Item1.Discountprice" oninput="setPrice(this)">
                                    </div>
                                </div>
                            }

                            <div class="col-md-4">
                                <label class="control-label col-md-3">应收金额：</label>
                                <div class="input-group">
                                    <input type="text" name="Actualprice" id="Actualprice" class="input-sm form-control" value="@Model.Item1.Actualprice" readonly="readonly">
                                </div>
                            </div>
                            @*<div class="col-md-4">
                                    <label class="control-label col-md-3">总已收金额：</label>
                                    <div class="input-group">
                                        <input type="text" name="ReceivedPrice" class="input-sm form-control" value="0.00" readonly="readonly">
                                    </div>
                                </div>*@
                        </div>
                        <div class="form-group">
                            @if (Model.Item1.ExamineStatus == ExamineStatus.已审核)
                            {
                                <div class="col-md-12">
                                    <label class="control-label col-md-3" style="width:132px">备注：</label>
                                    <div class="input-group">
                                        @*<input type="text" name="RemarksConten" class="input-sm form-control" value="@Model.Item1.RemarksConten" style="width:800px" readonly="readonly">*@

                                        <textarea name="RemarksConten" class="form-control" style="width:800px" readonly="readonly">@Model.Item1.RemarksConten</textarea>
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="col-md-12">
                                    <label class="control-label col-md-3" style="width:132px">备注：</label>
                                    <div class="input-group">
                                        @*<input type="text" name="RemarksConten" class="input-sm form-control" value="@Model.Item1.RemarksConten" style="width:800px">*@
                                        <textarea name="RemarksConten" class="form-control" style="width:800px">@Model.Item1.RemarksConten</textarea>
                                    </div>
                                </div>
                            }
                        </div>
                    </form>
                </div>
                <hr />
                <div id="data_list">
                    @if (Model.Item1.BalanceWayEnum == FwProject.Core.Restaurant.BalanceWayEnum.日结)
                    {
                        <div>
                            <table class="table table-bordered table-hover table-rowselected">
                                <thead>
                                    <tr>
                                        <th>货品型号</th>
                                        <th>本次配送箱数</th>
                                        <th>回收</th>
                                        <th>换货</th>
                                        <th>折损</th>
                                        <th>赠送</th>
                                        <th>退箱</th>
                                        <th>退数</th>
                                        <th>状态</th>
                                        <th>单价[元]</th>
                                        <th>应支付金额[元]</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in Model.Item2)
                                    {
                                        <tr>
                                            <td>@item.TypeNumberName</td>
                                            <td>@item.Distributioncount</td>
                                            <td>@item.Recoverycount</td>
                                            <td>@item.Exchangegoodscount</td>
                                            <td>@item.Damagecount</td>
                                            <td>@item.Givecount</td>
                                            <td>@item.Backboxcount</td>
                                            <td>@item.Backnumbercount</td>
                                            <td>@item.Pricestatus</td>
                                            <td>@item.TypeNumberPrice</td>
                                            <td>@item.SumPrice</td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    }
                    else
                    {
                        <div>
                            <table class="table table-bordered table-hover table-rowselected">
                                <thead>
                                    <tr>
                                        <th>货品型号</th>
                                        <th>箱数</th>
                                        <th>数量</th>
                                        <th>单价[元]</th>
                                        <th>金额[元]</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in Model.Item2)
                                    {
                                        <tr>
                                            <td>@item.TypeNumberName</td>
                                            <td>@item.SumDistributionBoxCount</td>
                                            <td>@item.SumDistributionCount</td>
                                            <td>@item.TypeNumberPrice</td>
                                            <td>@item.SumPrice</td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    }

                </div>

            </div>
        </div>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/js/DateComm.js"></script>
    <script>
        function FormAjaxCallbackgoback(data) {
            if (data.success) {
                layer.msg("审核成功！！");
                top.Refresh();
            } else {
                layer.msg("审核失败！！")
            }

        }


        $(document).ready(function () {

            $.getJSON("/Deposit/GetAgentPeoperData").done(function (data) {
                CommonAjaxCallback(data, function () {
                    bindSuggest(data.result);
                }, null);
            }).fail(function () {
                layer.msg('连接超时，获取经办人失败！', {
                    icon: 2,
                    time: 2000
                });
            });

            $('#modal_ajax').on('show.bs.modal', function (e) {
                $(this).addClass('loading');
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this); //$("#form_model_create").validate();
                        $("input[name='CarOld']").datepicker({ todayBtn: "linked", keyboardNavigation: !1, forceParse: !1, calendarWeeks: !0, autoclose: !0 });
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        $(this).removeClass('loading');


                        $('.btnDel').on('click', function () {
                            $(this).parent().parent().remove();
                        });

                    });
                }
            });
            $('#modal_ajax').on('hidden.bs.modal', function (e) {
                $(this).empty();
            });

            $('#btnExm').click(function () {
                $('#form').submit();
            });
        });

        function bindSuggest(data) {
            if ($("#dropdown-agentpeoperuserid") != undefined) {
                $role = $("#dropdown-agentpeoperuserid").bsSuggest({
                    effectiveFields: ["name"],
                    effectiveFieldsAlias: { "name": "姓名" },
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#EmployeeDriverid").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }
        function blurEmpty() {
            var cityObj = $("#dropdown-agentpeoperuserid");
            var DriverId = $("#EmployeeDriverid");
            if (cityObj.val() == "") {
                DriverId.attr("value", "");
            }
        }

        function setPrice(obj) {
            var TotalPrice = parseFloat($('#TotalPrice').val());
            var Actualprice = parseFloat($('#Actualprice').val());
            var ReceivedDiscount = parseFloat($('#ReceivedDiscount').val());
            if (ReceivedDiscount > TotalPrice) {
                $('#ReceivedDiscount').val(0);
            } else {
                $('#Actualprice').val(toFloat(TotalPrice - ReceivedDiscount));
            }

        }

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $('#modal_ajax').modal("hide");
                window.location.reload();
            }, successInfo);
        }
        var toFloat = function (value) {
            value = Math.round(parseFloat(value) * 100) / 100;
            if (value.toString().indexOf(".") < 0) {
                value = value.toString() + ".00";
            }
            return value;
        }


    </script>
}

